import config from '@/config'

export default {
    set: s => {
        const strHistory = localStorage.getItem(config.history) || ''
        let arrHistory = strHistory.split('/')
        if (arrHistory.length > 10) {
            arrHistory.splice(arrHistory.length - 1, 1)
        }
        if (arrHistory.includes(s)) {
            arrHistory.splice(arrHistory.indexOf(s), 1)
        }
        arrHistory.unshift(s)
        localStorage.setItem(config.history, arrHistory.join('/'))
    },
    get: () => {
        return  localStorage.getItem(config.history) ?  localStorage.getItem(config.history).split('/').filter(i => {
            return i
        }) : []
    },
    clear: () => {
        localStorage.removeItem(config.history)
    }
}